package net.yla.smartbus.core.constants;

import com.alibaba.fastjson.annotation.JSONType;
import net.yla.smartbus.core.exception.EnumNotFoundException;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 考勤状态枚举
 * @author ZhouChengLei
 * @date 2019/7/11 14:15
*/
@JSONType(serializeEnumAsJavaBean = true)
public enum AttendanceAuditEnum {
    /**
     * 考勤待提交
     */
    WAIT_COMMIT(0,"待提交"),

    /**
     * 待一审
     */
    WAIT_AUDIT(1,"待审核"),

    /**
     * 一审通过待二审
     */
    FIRST_AUDIT_PASS(2,"一审通过"),

    /**
     * 二审通过
     */
    SECOND_AUDIT_PASS(3,"二审通过");

    private int code;
    private String desc;
    AttendanceAuditEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }
    private static final Map<Integer, AttendanceAuditEnum> BY_VALUE_MAP = new LinkedHashMap<>();

    static {
        for (AttendanceAuditEnum attendanceAuditEnum : AttendanceAuditEnum.values()) {
            BY_VALUE_MAP.put(attendanceAuditEnum.getCode(), attendanceAuditEnum);
        }
    }

    /**
     * 根据code查询对应的处理结果类型枚举
     */
    public static AttendanceAuditEnum convertCode2Enum(int code) throws EnumNotFoundException {
        if (!BY_VALUE_MAP.containsKey(code)) {
            throw new EnumNotFoundException("枚举对应的code" + code + "不存在");
        }
        return BY_VALUE_MAP.get(code);
    }

    /**
     * 根据枚举name查询对应的处理结果类型枚举
     */
    public static AttendanceAuditEnum convertStr2Enum(String str) throws EnumNotFoundException {
        try {
            return AttendanceAuditEnum.valueOf(str);
        } catch (Exception e) {
            throw new EnumNotFoundException("枚举对应常量" + str + "不存在");
        }
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getName() {
        return this.name();
    }
}
